package com.tianqu.tms.www.attn.controller;

import java.util.List;

import com.tianqu.tms.core.base.Logger;
import com.tianqu.tms.core.base.TmsController;
import com.tianqu.tms.core.base.TxController;
import com.tianqu.tms.core.base.UserContext;
import com.tianqu.tms.core.exception.TmsException;
import com.tianqu.tms.core.exception.TransactionException;
import com.tianqu.tms.core.util.TmsConstants;
import com.tianqu.tms.entity.Attn;
import com.tianqu.tms.www.attn.viewhelper.AttnViewhelper;
import com.tianqu.tms.www.member.action.MemberUDTopListAction;

/**
 * @author zhangxueliang
 * 经办人一览列表
 */
public class AttnDeatilListController extends TmsController{

	private Logger logger = Logger.getLogger(AttnDeatilListController.class);

	public static final String PAGING = "paging";
	public static final String ATTNLIST = "attnList";
	@Override
	public void execute(UserContext uc) throws Exception {
		logger.debug(this.getClass().getName() + "#execute was called.");
		TxController controller = TxController.getTxController();

		// 添加事务提交异常捕获
		try {
			controller.begin();
			Attn entity = new Attn();
			if (uc.getAttribute(MemberUDTopListAction.PAGENO) != null) {
				entity.setPageNo(Integer.parseInt((String) uc
						.getAttribute(MemberUDTopListAction.PAGENO)));
			}
			if (uc.getAttribute(MemberUDTopListAction.MAXINDEX) != null) {
				entity.setMaxIndex(Integer.parseInt((String) uc
						.getAttribute(MemberUDTopListAction.MAXINDEX)));
			}
			if (uc.getAttribute(MemberUDTopListAction.SORTKEY) != null) {
				entity.setSortKey(Integer.parseInt((String) uc
						.getAttribute(MemberUDTopListAction.SORTKEY)));
			}
			if (uc.getAttribute(MemberUDTopListAction.ASC) != null) {
				entity.setAsc((new Boolean((String) uc
						.getAttribute(MemberUDTopListAction.ASC)))
						.booleanValue());
			}
			AttnViewhelper viewhelper = new AttnViewhelper();
			List<Attn> attnList = entity.findAllAttnInfo();
			viewhelper.setAttnList(attnList);
			uc.setAttribute(PAGING, entity);
			uc.setAttribute(TmsConstants.VIEWHELP,viewhelper);
			logger.debug(this.getClass().getName() + "#execute was completed.");
			controller.commit();
		} catch (Exception e) {
			try {
				controller.rollback();
			} catch (TransactionException e1) {
				throw new TmsException(TmsException.DB_TXCRROR, e1);
			}
			// 系统异常
			if (e instanceof TmsException) {
				throw e;
			}
			throw new TmsException(TmsException.DB_TXCRROR, e);
		}
	}

}
